home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / UTIL / SCREEN / CURSES01 / minix / c / update < prev    next >
Text File  |  1991-05-05  |  9KB  |  281 lines

  1. /****************************************************************/
  2. /* Doupdate() routine of the PCcurses package            */
  3. /*                                */
  4. /****************************************************************/
  5. /* This version of curses is based on ncurses, a curses version    */
  6. /* originally written by Pavel Curtis at Cornell University.    */
  7. /* I have made substantial changes to make it run on IBM PC's,    */
  8. /* and therefore consider myself free to make it public domain.    */
  9. /*        Bjorn Larsson (...mcvax!enea!infovax!bl)    */
  10. /****************************************************************/
  11. /* 1.0:    Release:                    870515    */
  12. /****************************************************************/
  13. /* Modified to run under the MINIX operating system by Don Cope */
  14. /* These changes are also released into the public domain.      */
  15. /*                             900906  */
  16. /****************************************************************/
  17.  
  18. #include <stdio.h>
  19. #include <curses.h>
  20. #include "curspriv.h"
  21.  
  22. static void clrupdate();        /* fwd declaration */
  23. static bool transformline();
  24. static void clearscreen();
  25. static void gotoxy();
  26. static void Putchar();
  27.  
  28. static WINDOW    *twin;            /* used by many routines */
  29.  
  30. #ifndef MINIX
  31.  
  32. static    char     atrtab[U[64] =        /* attribute encoding table. */
  33. {                    /* feel free to edit if your */
  34.   07,        /* NORMAL (0) */        /* display board supports all */
  35.   0x87,        /* BLINK */            /* possible combinations */
  36.   0,        /* BLANK */
  37.   0,        /* BLINK & BLANK */
  38.   0x0f,        /* BOLD */
  39.   0x8f,        /* BOLD & BLINK */
  40.   0,        /* BOLD & BLANK */
  41.   0,        /* BOLD & BLINK & BLANK */
  42.   0x70,        /* REVERSE (8) */
  43.   0xf0,        /* REVERSE & BLINK */
  44.   0,        /* REVERSE & BLANK */
  45.   0,        /* REVERSE & BLINK & BLANK */
  46.   0x78,        /* REVERSE & BOLD */
  47.   0xf8,        /* REVERSE & BOLD & BLINK */
  48.   0,        /* REVERSE & BOLD & BLANK */
  49.   0,        /* REVERSE & BOLD & BLINK & BLANK */
  50.   0x70,        /* STANDOUT (10) */
  51.   0x8f,        /* STANDOUT & BLINK */
  52.   0,        /* STANDOUT & BLANK */
  53.   0,        /* STANDOUT & BLINK & BLANK */
  54.   0x0f,        /* STANDOUT & BOLD */
  55.   0x8f,        /* STANDOUT & BOLD & BLINK */
  56.   0,        /* STANDOUT & BOLD & BLANK */
  57.   0,        /* STANDOUT & BOLD & BLINK & BLANK */
  58.   0x70,        /* STANDOUT & REVERSE (18) */
  59.   0xf0,        /* STANDOUT & REVERSE & BLINK */
  60.   0,        /* STANDOUT & REVERSE & BLANK */
  61.   0,        /* STANDOUT & REVERSE & BLINK & BLANK */
  62.   0x70,        /* STANDOUT & REVERSE & BOLD */
  63.   0xf0,        /* STANDOUT & REVERSE & BOLD & BLINK */
  64.   0,        /* STANDOUT & REVERSE & BOLD & BLANK */
  65.   0,        /* STANDOUT & REVERSE & BOLD & BLINK & BLANK */
  66.   1,        /* UNDERLINE (20) */
  67.   0x81,        /* UNDERLINE & BLINK */
  68.   0,        /* UNDERLINE & BLANK */
  69.   0,        /* UNDERLINE & BLINK & BLANK */
  70.   9,        /* UNDERLINE & BOLD */
  71.   0x89,        /* UNDERLINE & BOLD & BLINK */
  72.   0,        /* UNDERLINE & BOLD & BLANK */
  73.   0,        /* UNDERLINE & BOLD & BLINK & BLANK */
  74.   0x70,        /* UNDERLINE & REVERSE (28) */
  75.   0xf0,        /* UNDERLINE & REVERSE & BLINK */
  76.   0,        /* UNDERLINE & REVERSE & BLANK */
  77.   0,        /* UNDERLINE & REVERSE & BLINK & BLANK */
  78.   0x79,        /* UNDERLINE & REVERSE & BOLD */
  79.   0xf9,     /* UNDERLINE & REVERSE & BOLD & BLINK */
  80.   0,        /* UNDERLINE & REVERSE & BOLD & BLANK */
  81.   0,        /* UNDERLINE & REVERSE & BOLD & BLINK & BLANK */
  82.   9,        /* UNDERLINE & STANDOUT (30) */
  83.   0x89,        /* UNDERLINE & STANDOUT & BLINK */
  84.   0,        /* UNDERLINE & STANDOUT & BLANK */
  85.   0,        /* UNDERLINE & STANDOUT & BLINK & BLANK */
  86.   9,        /* UNDERLINE & STANDOUT & BOLD */
  87.   0x89,        /* UNDERLINE & STANDOUT & BOLD & BLINK */
  88.   0,        /* UNDERLINE & STANDOUT & BOLD & BLANK */
  89.   0,        /* UNDERLINE & STANDOUT & BOLD & BLINK & BLANK */
  90.   0x70,        /* UNDERLINE & STANDOUT & REVERSE (38) */
  91.   0xf0,        /* UNDERLINE & STANDOUT & REVERSE & BLINK */
  92.   0,        /* UNDERLINE & STANDOUT & REVERSE & BLANK */
  93.   0,        /* UNDERLINE & STANDOUT & REVERSE & BLINK & BLANK */
  94.   0x70,        /* UNDERLINE & STANDOUT & REVERSE & BOLD */
  95.   0xf0,        /* UNDERLINE & STANDOUT & REVERSE & BOLD & BLINK */
  96.   0,        /* UNDERLINE & STANDOUT & REVERSE & BOLD & BLANK */
  97.   0,        /* UNDERLINE & STANDOUT & REVERSE & BOLD & BLINK & BLANK */
  98. };
  99. #endif
  100.  
  101. /****************************************************************/
  102. /* Doupdate() updates the physical screen to look like _curs-   */
  103. /* var.tmpwin if curscr is not 'Clear-marked'. Otherwise it    */
  104. /* updates the screen to look like curscr.            */
  105. /****************************************************************/
  106.  
  107. void doupdate()
  108. {
  109.   register int         i;
  110.  
  111.   twin   = _cursvar.tmpwin;
  112.   if (curscr->_clear)
  113.       clrupdate(curscr);
  114.   else
  115.   {
  116.     if (twin->_clear)
  117.         clrupdate(twin);
  118.     else
  119.     {
  120.       for (i=0; i < LINES; i++)
  121.       if (twin->_minchng[i] != _NO_CHANGE)
  122.           if (transformline(i))
  123.       break;
  124.     } /* else */
  125.   } /* else */
  126.   curscr->_curx = twin->_curx;
  127.   curscr->_cury = twin->_cury;
  128.   gotoxy(curscr->_cury, curscr->_curx);
  129.   fflush(stdout);
  130. } /* doupdate */
  131.  
  132. /****************************************************************/
  133. /* Clrupdate(scr) updates the screen by clearing it and then    */
  134. /* redraw it in it's entirety. If _cursvar.refrbrk is TRUE, and    */
  135. /* there is pending input characters, the update will be pre-    */
  136. /* maturely terminated.                        */
  137. /****************************************************************/
  138.  
  139. static void clrupdate(scr)
  140. WINDOW    *scr;
  141. {
  142.   register int        *src;
  143.   register int        *dst;
  144.   register int         i;
  145.   register int         j;
  146.   static   WINDOW    *w;
  147.  
  148.   w = curscr;
  149.   
  150.   if (scr != w)                /* copy scr to curscr */
  151.   {
  152.     for (i=0; i < LINES; i++)
  153.     {
  154.       src = scr->_line[i];
  155.       dst = w->_line[i];
  156.       for (j=0; j < COLS; j++)
  157.       *dst++ = *src++;
  158.     } /* for */
  159.   } /* if */
  160.   clearscreen();            /* clear physical screen */
  161.   scr->_clear = FALSE;
  162.   for (i=0; i < LINES; i++)        /* update physical screen */
  163.   {
  164.     src = w->_line[i];
  165.     j=0;
  166.     while(j < COLS)
  167.     {
  168.       if (*src != (' ' | ATR_NRM))
  169.       {
  170.         gotoxy(i,j);
  171.         while (j<COLS && (*src != (' ' | ATR_NRM)))
  172.         {
  173.           Putchar(scr, *src++);
  174.           j++;
  175.         }
  176.       }
  177.       else
  178.       {
  179.         src++;
  180.         j++;
  181.       }
  182.     } /* for */
  183.     if(_cursvar.refrbrk && _cursespendch())
  184.     return;
  185.   } /* for */
  186.   fflush(stdout);
  187. } /* clrupdate */
  188.  
  189. /****************************************************************/
  190. /* Transformline() updates the given physical line to look    */
  191. /* like the corresponding line in _cursvar.tmpwin. Transform-    */
  192. /* returns 1 if premature refresh end is allowed, and there is    */
  193. /* an input character pending.                    */
  194. /****************************************************************/
  195.  
  196. static bool transformline(lineno)
  197. register int    lineno;
  198. {
  199.   register int        *dstp;
  200.   register int        *srcp;
  201.   register int        *dstc;
  202.   register int        *srcc;
  203.   static   int         x;
  204.   static   int         endx;
  205.  
  206.   x    = twin->_minchng[lineno];
  207.   endx = twin->_maxchng[lineno];
  208.   dstp = curscr->_line[lineno] + x;
  209.   srcp = twin->_line[lineno] + x;
  210.   dstc = curscr->_colors;
  211.   srcc = twin->_colors;
  212.   
  213.   while (x <= endx)
  214.   {
  215.     if((*dstp != *srcp) || (*dstc != *srcc))
  216.     {
  217.       gotoxy(lineno,x);
  218.       while (x<= endx && ((*dstp != *srcp) || (*dstc != *srcc)))
  219.       {
  220.         Putchar(twin, *srcp);
  221.         *dstp++ = *srcp++;
  222.         x++;
  223.       }
  224.     }
  225.     else
  226.     {
  227.       *dstp++ = *srcp++;
  228.       x++;
  229.     }
  230.   } /* for */
  231.   twin->_minchng[lineno] = _NO_CHANGE;
  232.   twin->_maxchng[lineno] = _NO_CHANGE;
  233.   return (_cursvar.refrbrk && _cursespendch());
  234. } /* transformline */
  235.  
  236. /****************************************************************/
  237. /* Clearscreen() clears the physical screen and puts the cursor    */
  238. /* in the home position.                    */
  239. /****************************************************************/
  240.  
  241. static void clearscreen()
  242. {
  243.   _cursesclrscr();
  244.   gotoxy(0,0);
  245. } /* clearscreen */
  246.  
  247. /****************************************************************/
  248. /* Gotoxy() moves the physical cursor to the desired address on    */
  249. /* the screen. We don't optimize here - on a PC, it takes more    */
  250. /* time to optimize than to do things directly.            */
  251. /****************************************************************/
  252.  
  253. static void gotoxy(row,col)
  254. int row, col;
  255. {
  256.   if((_cursvar.cursrow == row) && (_cursvar.curscol == col))
  257.   return;
  258.   _cursescursor(0,row,col);
  259.   _cursvar.cursrow = row;
  260.   _cursvar.curscol = col;
  261. } /* gotoxy */
  262.  
  263. /****************************************************************/
  264. /* Putchar() writes a character, with attributes, to the physi-    */
  265. /* cal screen, but avoids writing to the lower right screen    */
  266. /* position.                            */
  267. /****************************************************************/
  268.  
  269. static void Putchar(win, ch)
  270. WINDOW *win;
  271. int ch;
  272. {
  273.   if ((_cursvar.cursrow < LINES) || (_cursvar.curscol < COLS))
  274. #ifdef MINIX
  275.   _cursessetcolor(win->_colors); 
  276.   _cursescattr(0,ch,ch >> 8, 0);
  277. #else
  278.   _cursescattr(0,ch,atrtab[(ch >> 8) & 0x3f],1);
  279. #endif
  280. } /* Putchar */
  281.